# -*- coding: utf-8 -*-

<%!
    from toscawidgets.widgets.extJS.form import DateField
%>

{
%if isId:
       id:'${name}',
%endif       
       header: '${header}',
       dataIndex: '${dataIndex}',
       width: ${width},
       sortable: true,
       editor: ${editor.display(value_for(editor), **args_for(editor))}
       
       %if isinstance(editor,DateField):
			, renderer : Ext.util.Format.dateRenderer('d/m/Y')       
       %elif gridName!='':
	        ,         
	        renderer : function (value, p, record, rowIndex, colIndex, ds) {
			
				var val = "";
        
		        var cm = Ext.getCmp("${gridName}").getColumnModel();
		        var ce = cm.getCellEditor(colIndex, rowIndex);
		        var store = ce.field.store;
		        
		        var value = record.data.${dataIndex}
		
				if(value != undefined && value !=''){
					store.load();
					
					var rec = store.getAt(store.find('id',value));
					while(rec==undefined){
						rec = store.getAt(store.find('id',value));
					}
		        	val = rec.data.${editor.displayField};
				}
		        return val;
			},
			
			sortType : function (value, p, record, rowIndex, colIndex, ds) {
			
				var val = "";
        
		        var cm = Ext.getCmp("${gridName}").getColumnModel();
		        var ce = cm.getCellEditor(colIndex, rowIndex);
		        var store = ce.field.store;
		        
		        var value = record.data.${dataIndex}
		
				if(value != undefined && value !=''){
					var rec = store.getAt(store.find('id',value));
					if(rec==undefined){
						store.load();
						rec = store.getAt(store.find('id',value));
					}
		        	val = rec.data.${editor.displayField};
				}
		        return val;
			}
		%endif       
}
 